package com.chartHandle.excelService.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.chartHandle.excelService.listen.BaseSmokeInfoListener;
import com.chartHandle.excelService.service.ReadOrderInfoService;
import com.projectCommon.bean.easyExcel.CSVSmokeInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;

@Service
@Slf4j
public class ReadOrderInfoServiceImpl implements ReadOrderInfoService {
    @Override
    public  List<CSVSmokeInfo> getOrderPictureByCSVOrderFile(byte[] csvByte) {
        InputStream inputStream = new ByteArrayInputStream(csvByte);
//        读取csv文件 获取list集合
        List<CSVSmokeInfo> baseSmokeInfos = EasyExcel
                .read(inputStream,
                        CSVSmokeInfo.class,
                        new BaseSmokeInfoListener())
                .charset(Charset.forName("GBK"))
                .excelType(ExcelTypeEnum.CSV)
                .sheet()
                .doReadSync();
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return baseSmokeInfos;
    }

}
